from itsdangerous import TimedJSONWebSignatureSerializer
from django.conf import settings


def dumps(dict1, expire):
    serializer = TimedJSONWebSignatureSerializer(settings.SECRET_KEY, expires_in=expire)
    return serializer.dumps(dict1).decode()


def loads(str1, expire):
    serializer = TimedJSONWebSignatureSerializer(settings.SECRET_KEY, expires_in=expire)
    try:
        dict1 = serializer.loads(str1)
    except:
        return None
    else:
        return dict1
